//
//  MeetingTheStormFromTableViewCell.m
//  Gxj
//
//  Created by 刘伟 on 2017/9/7.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "MeetingTheStormFromTableViewCell.h"

@implementation MeetingTheStormFromTableViewCell
// 重写表格位置，使每一行cell都分隔开
- (void)setFrame:(CGRect)frame{
    //    frame.origin.x += 10;
    //    frame.origin.y += 10;
    frame.size.height -= 5;
    //    frame.size.width -= 20;
    [super setFrame:frame];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self.contentView addSubview:self.userHeadView];
        [self.userHeadView addSubview:self.iconTouxiang]; // 头像
        [self.contentView addSubview:self.nameText]; // 名称
        [self.contentView addSubview:self.guanzhuBut]; // 关注
        [self.contentView addSubview:self.iconXunzhang]; // 等级勋章
        [self.contentView addSubview:self.textDengji]; // 等级
        [self.contentView addSubview:self.iconGuankan]; // 浏览人数图片
        [self.contentView addSubview:self.numLable];  // 浏览人数
        [self.imageFabiao addSubview:self.contentText]; // 标题
        [self.contentView addSubview:self.iconShijian];  //  时间图标
        [self.contentView addSubview:self.shiJianText];  //  发布时间
        [self.shadowView  addSubview:self.shangYeText];
        [self.contentView addSubview:self.shadowView]; //  内容简介
        [self.contentView addSubview:self.imageFabiao];  // 用户发表图片
        [self.contentView addSubview:self.zuijiaText];  //  最佳评论标签
        [self.contentView addSubview:self.thumpUp];
        [self.contentView addSubview:self.thumpUpNum];
        [self.imageFabiao addSubview:self.labellingLab];
        [self.imageFabiao addSubview:self.labellingLab1];
        [self.imageFabiao addSubview:self.countdown];
        
        [self.contentView addSubview:self.gotoBtn];
        
        [self showNaoBaoCell];
    }
    return self;
}

- (void)showNaoBaoCell
{
    _userHeadView.sd_layout
    .topSpaceToView(self.contentView, kHeightScale(11))
    .leftSpaceToView(self.contentView, kWidthScale(15))
    .widthIs(kWidthScale(25))
    .heightIs(kHeightScale(25));
    
    _iconTouxiang.sd_layout
    .topSpaceToView(self.userHeadView, kHeightScale(1.5))
    .leftSpaceToView(self.userHeadView, kWidthScale(1.5))
    .widthIs(kWidthScale(22))
    .heightIs(kHeightScale(22));
    
    _nameText.sd_layout
    .topSpaceToView(self.contentView,kHeightScale(10))
    .leftSpaceToView(self.userHeadView,kWidthScale(5))
    .widthIs(kWidthScale(150))
    .autoHeightRatio(0);
    
    _guanzhuBut.sd_layout
    .topSpaceToView(self.contentView,kHeightScale(10))
    .rightSpaceToView(self.contentView,kWidthScale(15))
    .widthIs(kWidthScale(44))
    .heightIs(kHeightScale(25));
    
    _iconXunzhang.sd_layout
    .topSpaceToView(self.nameText,kHeightScale(3))
    .leftEqualToView(self.nameText)
    .widthIs(kWidthScale(11))
    .heightIs(kHeightScale(11));
    
    _textDengji.sd_layout
    .centerYEqualToView(self.iconXunzhang)
    .leftSpaceToView(self.iconXunzhang,kWidthScale(3))
    .widthIs(kWidthScale(30))
    .autoHeightRatio(0);
    
    _iconShijian.sd_layout
    .topSpaceToView(self.userHeadView,kHeightScale(5))
    .leftEqualToView(self.userHeadView)
    .widthIs(kWidthScale(13))
    .heightIs(kHeightScale(13));
    
    _shiJianText.sd_layout
    .centerYEqualToView(self.iconShijian)
    .leftSpaceToView(self.iconShijian,kWidthScale(5))
    .autoHeightRatio(0);
    [_shiJianText setSingleLineAutoResizeWithMaxWidth:(40)];
    
    _iconGuankan.sd_layout
    .centerYEqualToView(self.iconShijian)
    .leftSpaceToView(self.shiJianText,kWidthScale(10))
    .widthIs(kWidthScale(13))
    .heightIs(kHeightScale(8.6));
    
    _numLable.sd_layout
    .centerYEqualToView(self.iconGuankan)
    .leftSpaceToView(self.iconGuankan,kWidthScale(5))
    .autoHeightRatio(0);
    [_numLable setSingleLineAutoResizeWithMaxWidth:(40)];
    
    _thumpUp.sd_layout
    .centerYEqualToView(self.iconShijian)
    .leftSpaceToView(self.numLable,kWidthScale(10))
    .widthIs(kWidthScale(12))
    .heightIs(kHeightScale(12));
    
    _thumpUpNum.sd_layout
    .centerYEqualToView(self.thumpUp)
    .leftSpaceToView(self.thumpUp,kWidthScale(5))
    .autoHeightRatio(0);
    [_thumpUpNum setSingleLineAutoResizeWithMaxWidth:(40)];
    
    _imageFabiao.sd_layout
    .topSpaceToView(self.shiJianText,kHeightScale(5))
    .leftEqualToView(self.userHeadView)
    .rightEqualToView(self.guanzhuBut)
    .heightIs(kHeightScale(110));
    
    _shadowView.sd_layout
    .topSpaceToView(self.imageFabiao,kHeightScale(10))
    .leftEqualToView(self.iconShijian)
    .rightEqualToView(self.guanzhuBut)
    .heightIs(kHeightScale(49));
    
    _shangYeText.sd_layout
    .topSpaceToView(self.shadowView, 0)
    .leftSpaceToView(self.shadowView, 0)
    .rightSpaceToView(self.shadowView, 0)
    .heightIs(kHeightScale(49));
    
    _contentText.sd_layout
    .bottomEqualToView(self.imageFabiao)
    .leftEqualToView(self.imageFabiao)
    .rightEqualToView(self.imageFabiao)
    .heightIs(kHeightScale(20));
    
    _labellingLab.sd_layout
    .topSpaceToView(self.imageFabiao,kHeightScale(5))
    .leftSpaceToView(self.imageFabiao,kWidthScale(5))
    .widthIs(kWidthScale(35))
    .heightIs(kHeightScale(15));
    
    _labellingLab1.sd_layout
    .topSpaceToView(self.imageFabiao,kHeightScale(5))
    .leftSpaceToView(self.labellingLab,kWidthScale(5))
    .widthIs(kWidthScale(35))
    .heightIs(kHeightScale(15));
    
    _countdown.sd_layout
    .centerYEqualToView(self.labellingLab)
    .rightSpaceToView(self.imageFabiao,kWidthScale(5))
    .widthIs(kWidthScale(45))
    .heightIs(kHeightScale(15));
    //    [_countdown setSingleLineAutoResizeWithMaxWidth:kWidthScale(45)];
    
    _zuijiaText.sd_layout
    .topSpaceToView(self.shadowView,kHeightScale(10))
    .leftEqualToView(self.shadowView)
    .autoHeightRatio(0);
    [_zuijiaText setSingleLineAutoResizeWithMaxWidth:kWidthScale(80)];
    
    _gotoBtn.sd_layout
    .centerYEqualToView(self.zuijiaText)
    .rightEqualToView(self.imageFabiao)
    .widthIs(kWidthScale(56))
    .heightIs(kHeightScale(20));
    
    //    for (int i = 0; i < model.industryid.count; i++) {
    //        _labellingLab = [[UILabel alloc] initWithFrame:CGRectMake(kWidthScale(5) + kWidthScale(40) * i, kHeightScale(5), kWidthScale(35), kHeightScale(15))];
    //
    //        _labellingLab.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
    //        _labellingLab.text = model.industryid[i];
    //        _labellingLab.textColor = [UIColor colorWithWhite:0.9 alpha:1];
    //        _labellingLab.font = [UIFont systemFontOfSize:kWidthScale(9)];
    //        _labellingLab.textAlignment = NSTextAlignmentCenter;
    //        _labellingLab.layer.cornerRadius = kWidthScale(5);
    //        _labellingLab.layer.masksToBounds = YES;
    //        [self.labelView addSubview:self.labellingLab];
    //    }
    
    //    for (int i = 0; i < 5; i++) {
    //        _bestHeadImage = [[UIImageView alloc] initWithFrame:CGRectMake(kWidthScale(84) * (i+1) - (66*i), kHeightScale(270), kWidthScale(23), kHeightScale(23))];
    //        if (model.bestuser.count) {
    //            [_bestHeadImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[_model.bestuser[i] objectForKey:@"head_img"]]]];
    //        }
    //        [self.contentView addSubview:self.bestHeadImage]; //  最佳评论用户头像
    //    }
    [self.contentView addSubview:self.addTX];   // ➕
    
    //    if (model.bestuser.count) {
    //        _addTX.sd_layout
    //        .centerYEqualToView(self.zuijiaText)
    //        .leftSpaceToView(self.bestHeadImage,kWidthScale(-5))
    //        .widthIs(kWidthScale(23))
    //        .heightIs(kHeightScale(23));
    //    }else{
    _addTX.sd_layout
    .centerYEqualToView(self.zuijiaText)
    .leftSpaceToView(self.zuijiaText,kWidthScale(15))
    .widthIs(kWidthScale(23))
    .heightIs(kHeightScale(23));
    //    }
}
// 头像
- (UIButton *)iconTouxiang
{
    if (!_iconTouxiang)
    {
        _iconTouxiang = [UIButton buttonWithType:UIButtonTypeCustom];
        _iconTouxiang.layer.cornerRadius = kWidthScale(11);
        _iconTouxiang.layer.masksToBounds = YES;
        [_iconTouxiang setImage:[UIImage imageNamed:@"toixiang"] forState:0];
    }
    return _iconTouxiang;
}
// 名字
- (UILabel *)nameText
{
    if (!_nameText)
    {
        _nameText = [[UILabel alloc] init];
        _nameText.text = @"后悔的小公主";
        _nameText.font = [UIFont systemFontOfSize:kWidthScale(12)];
        _nameText.textColor = [UIColor colorWithHexString:@"#333333"];
    }
    return _nameText;
}
// 关注
- (UIButton *)guanzhuBut
{
    if (!_guanzhuBut)
    {
        _guanzhuBut = [UIButton buttonWithType:UIButtonTypeCustom];
        [_guanzhuBut setBackgroundImage:[UIImage imageNamed:@"guanzhu"] forState:0];
        _guanzhuBut.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _guanzhuBut;
}
// 等级勋章
- (UIImageView *)iconXunzhang
{
    if (!_iconXunzhang)
    {
        _iconXunzhang = [[UIImageView alloc] init];
        _iconXunzhang.image=[UIImage imageNamed:@"dengjis"];
    }
    return _iconXunzhang;
}
// 等级
- (UILabel *)textDengji
{
    if (!_textDengji)
    {
        _textDengji = [[UILabel alloc] init];
        _textDengji.text = @"1级";
        _textDengji.textColor=[UIColor colorWithHexString:@"#999999"];
        _textDengji.font=[UIFont systemFontOfSize:kWidthScale(11)];
    }
    return _textDengji;
}
// 观看人数图片
- (UIImageView *)iconGuankan
{
    if (!_iconGuankan)
    {
        _iconGuankan = [[UIImageView alloc] init];
        _iconGuankan.image=[UIImage imageNamed:@"liulans"];
    }
    return _iconGuankan;
}
// 观看人数
- (UILabel *)numLable
{
    if (!_numLable)
    {
        _numLable = [[UILabel alloc] init];
        _numLable.text=@"13";
        _numLable.textColor = [UIColor colorWithHexString:@"#999999"];
        _numLable.font=[UIFont systemFontOfSize:kWidthScale(12)];
    }
    return _numLable;
}
// 标题
- (UILabel *)contentText
{
    if (!_contentText)
    {
        _contentText = [[UILabel alloc] init];
        _contentText.textColor = [UIColor whiteColor];
        _contentText.text=@"什么时候觉得，数据分析真的非常有用";
        _contentText.font = [UIFont systemFontOfSize:kWidthScale(13)];
        _contentText.textAlignment = NSTextAlignmentCenter;
        _contentText.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4];
    }
    return _contentText;
}
// 时间图标
- (UIImageView *)iconShijian
{
    if (!_iconShijian)
    {
        _iconShijian = [[UIImageView alloc] init];
        _iconShijian.image = [UIImage imageNamed:@"time"];
    }
    return _iconShijian;
}
// 具体发布时间
- (UILabel *)shiJianText
{
    if (!_shiJianText)
    {
        _shiJianText = [[UILabel alloc] init];
        _shiJianText.text = @"8.15";
        _shiJianText.textColor = [UIColor colorWithHexString:@"#999999"];
        _shiJianText.font = [UIFont systemFontOfSize:kWidthScale(12)];
        _shiJianText.textAlignment = NSTextAlignmentLeft;
    }
    return _shiJianText;
}
// 内容简介
- (KQlable *)shangYeText
{
    if (!_shangYeText)
    {
        _shangYeText = [[KQlable alloc] init];
        _shangYeText.text = @"风暴简介：个环境可凉快和包教包零零落落零零落落零零落落零零落落零零落落啦啦啦";
        _shangYeText.numberOfLines = 0;
        _shangYeText.backgroundColor = [UIColor colorWithRed:251.0/255.0 green:251.0/255.0 blue:251.0/255.0 alpha:1];
        _shangYeText.textColor = [UIColor colorWithHexString:@"#666666"];
        _shangYeText.font = [UIFont systemFontOfSize:kWidthScale(11)];
        _shangYeText.layer.cornerRadius = kWidthScale(12);
        _shangYeText.layer.masksToBounds = YES;
        [KQlable changeLineSpaceForLabel:_shangYeText WithSpace:5.0f];
        
    }
    return _shangYeText;
}

// 用户发表图片
- (UIImageView *)imageFabiao
{
    if (!_imageFabiao)
    {
        _imageFabiao = [[UIImageView alloc] init];
        _imageFabiao.image=[UIImage imageNamed:@"ditu"];
        _imageFabiao.layer.cornerRadius = kWidthScale(12);
        _imageFabiao.layer.masksToBounds = YES;
    }
    return _imageFabiao;
}

- (UILabel *)labellingLab
{
    if (!_labellingLab)
    {
        _labellingLab = [[UILabel alloc] init];
        _labellingLab.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
        _labellingLab.textColor = [UIColor colorWithWhite:1 alpha:1];
        _labellingLab.font = [UIFont systemFontOfSize:kWidthScale(9)];
        _labellingLab.textAlignment = NSTextAlignmentCenter;
        _labellingLab.layer.cornerRadius = kWidthScale(5);
        _labellingLab.layer.masksToBounds = YES;
    }
    return _labellingLab;
}

- (UILabel *)labellingLab1
{
    if (!_labellingLab1)
    {
        _labellingLab1 = [[UILabel alloc] init];
        _labellingLab1.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
        _labellingLab1.textColor = [UIColor colorWithWhite:1 alpha:1];
        _labellingLab1.font = [UIFont systemFontOfSize:kWidthScale(9)];
        _labellingLab1.textAlignment = NSTextAlignmentCenter;
        _labellingLab1.layer.cornerRadius = kWidthScale(5);
        _labellingLab1.layer.masksToBounds = YES;
    }
    return _labellingLab1;
}

// 最佳评论
- (UILabel *)zuijiaText
{
    if (!_zuijiaText)
    {
        _zuijiaText = [[UILabel alloc] init];
        _zuijiaText.textColor = [UIColor colorWithHexString:@"#666666"];
        _zuijiaText.font = [UIFont systemFontOfSize:kWidthScale(12)];
        _zuijiaText.text = @"席位(18/18)";
        [_zuijiaText updateLayout];
    }
    return _zuijiaText;
}

// ➕
- (UIButton *)addTX
{
    if (!_addTX)
    {
        _addTX = [UIButton buttonWithType:UIButtonTypeCustom];
        [_addTX setBackgroundImage:[UIImage imageNamed:@"jia"] forState:UIControlStateNormal];
    }
    return _addTX;
}

- (UIView *)shadowView
{
    if (!_shadowView)
    {
        _shadowView = [[UIView alloc] init];
        _shadowView.layer.shadowColor = [UIColor blackColor].CGColor;
        _shadowView.layer.shadowOffset = CGSizeMake(0, 1);
        _shadowView.layer.shadowOpacity = 0.2;
        _shadowView.clipsToBounds = NO;
    }
    return _shadowView;
}

- (UIView *)userHeadView
{
    if (!_userHeadView)
    {
        _userHeadView = [[UIView alloc] init];
        _userHeadView.backgroundColor = [UIColor colorWithRed:(213.0/255) green:(213.0/255) blue:(213.0/255) alpha:1];;
        _userHeadView.layer.masksToBounds=YES;
        _userHeadView.layer.cornerRadius = 12.5;
        _userHeadView.layer.shadowColor = [UIColor blackColor].CGColor;
        _userHeadView.layer.shadowOffset = CGSizeMake(-3, 1);
        _userHeadView.layer.shadowOpacity = 0.4;
        _userHeadView.layer.shadowRadius = 2.0;
        _userHeadView.clipsToBounds = NO;
    }
    return _userHeadView;
}

- (UIButton *)thumpUp
{
    if (!_thumpUp)
    {
        _thumpUp = [UIButton buttonWithType:UIButtonTypeCustom];
        [_thumpUp setBackgroundImage:[UIImage imageNamed:@"zans"] forState:UIControlStateNormal];
    }
    return _thumpUp;
}

- (UILabel *)thumpUpNum
{
    if (!_thumpUpNum)
    {
        _thumpUpNum = [[UILabel alloc] init];
        _thumpUpNum.text = @"1111";
        _thumpUpNum.textColor = [UIColor colorWithHexString:@"#999999"];
        _thumpUpNum.font = [UIFont systemFontOfSize:kWidthScale(12)];
    }
    return _thumpUpNum;
}

- (UILabel *)countdown
{
    if (!_countdown)
    {
        _countdown = [[UILabel alloc] init];
        _countdown.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
        _countdown.textColor = [UIColor colorWithWhite:1 alpha:1];
        _countdown.font = [UIFont systemFontOfSize:kWidthScale(9)];
        _countdown.textAlignment = NSTextAlignmentCenter;
        _countdown.layer.cornerRadius = kWidthScale(5);
        _countdown.layer.masksToBounds = YES;
        _countdown.text = @"8:00";
    }
    return _countdown;
}

- (UIButton *)gotoBtn
{
    if (!_gotoBtn)
    {
        _gotoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_gotoBtn setImage:[UIImage imageNamed:@"jinruhuiyilb"] forState:0];
        _gotoBtn.layer.cornerRadius = kWidthScale(8);
        _gotoBtn.layer.masksToBounds = YES;
    }
    return _gotoBtn;
}
@end
